<template>
  <div class="register-page">
    <div class="register-container">
      <div class="register-header">
        <h1>DeepSeek Chat</h1>
        <p class="subtitle">创建您的账号</p>
      </div>
      
      <form @submit.prevent="handleRegister" class="register-form">
        <div class="form-group">
          <label>用户名</label>
          <div class="input-wrapper">
            <span class="icon">👤</span>
            <input 
              type="text" 
              v-model="username" 
              placeholder="请输入用户名"
              required
            >
          </div>
        </div>
        
        <div class="form-group">
          <label>密码</label>
          <div class="input-wrapper">
            <span class="icon">🔒</span>
            <input 
              :type="showPassword ? 'text' : 'password'"
              v-model="password" 
              placeholder="请输入密码"
              required
            >
            <span 
              class="icon clickable" 
              @click="showPassword = !showPassword"
            >
              {{ showPassword ? '👁️' : '👁️‍🗨️' }}
            </span>
          </div>
        </div>

        <div class="form-group">
          <label>确认密码</label>
          <div class="input-wrapper">
            <span class="icon">🔒</span>
            <input 
              :type="showPassword ? 'text' : 'password'"
              v-model="confirmPassword" 
              placeholder="请再次输入密码"
              required
            >
          </div>
        </div>
        
        <button type="submit" :disabled="loading" class="register-button">
          <span v-if="!loading">注 册</span>
          <span v-else class="loading-dots">
            <span>.</span><span>.</span><span>.</span>
          </span>
        </button>
      </form>

      <div class="login-hint">
        已有账号？ <a href="#" @click.prevent="goToLogin" class="login-link">返回登录</a>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const username = ref('');
const password = ref('');
const confirmPassword = ref('');
const loading = ref(false);
const showPassword = ref(false);

const handleRegister = async () => {
  if (password.value !== confirmPassword.value) {
    alert('两次输入的密码不一致');
    return;
  }

  try {
    loading.value = true;
    // 模拟注册
    await new Promise(resolve => setTimeout(resolve, 1000));
    alert('注册成功！');
    await router.push('/login');
  } catch (error) {
    console.error('注册失败:', error);
    alert('注册失败，请稍后重试');
  } finally {
    loading.value = false;
  }
};

const goToLogin = () => {
  router.push('/login');
};
</script>

<style scoped>
.register-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: 
    linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.1) 100%),
    linear-gradient(to right, #2c3e50, #3498db);
  background-size: 400% 400%;
  animation: gradient 15s ease infinite;
  padding: 20px;
}

@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.register-container {
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  padding: 40px;
}

.register-header {
  text-align: center;
  margin-bottom: 40px;
}

.register-header h1 {
  margin: 0;
  color: #1a1a1a;
  font-size: 28px;
  font-weight: 600;
}

.subtitle {
  margin: 8px 0 0;
  color: #666;
  font-size: 14px;
}

.form-group {
  margin-bottom: 24px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #1a1a1a;
  font-size: 14px;
  font-weight: 500;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: #f5f7fa;
  border-radius: 12px;
  transition: all 0.3s ease;
}

.input-wrapper:focus-within {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

.icon {
  padding: 0 12px;
  color: #666;
  user-select: none;
}

.clickable {
  cursor: pointer;
}

input {
  flex: 1;
  padding: 12px 0;
  border: none;
  background: transparent;
  font-size: 14px;
  color: #1a1a1a;
  outline: none;
}

input::placeholder {
  color: #999;
}

.register-button {
  width: 100%;
  padding: 14px;
  background: #007AFF;
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.register-button:hover {
  background: #0056b3;
  transform: translateY(-1px);
}

.register-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

.login-hint {
  margin-top: 24px;
  text-align: center;
  font-size: 14px;
  color: #666;
}

.login-link {
  color: #007AFF;
  text-decoration: none;
  font-weight: 500;
}

.login-link:hover {
  text-decoration: underline;
}

@media (max-width: 480px) {
  .register-container {
    padding: 30px 20px;
  }
}
</style> 